// pages/approveDetail/approveDetail.js
import { getMateriaBorrowInfo,getAssetBorrowInfo,getAssetRepairDetailInfo,
  getAssetReturnDetailInfo } from "@/api/approve.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseList:[], //基础数据
    dataList:[], //列表数据
    process:{} //审批数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {      
    //console.log("this.data.approve",options)
    this.setData({
      process:JSON.parse((options.approve))
    })
    console.log("this.data.approve",this.data.process)
    //0资产借用申请 1耗材领用申请 2资产报修申请 3资产归还申请
    if(this.data.process.processType=="资产借用申请"){      
      this.getAssetBorrowData() 
    }else if(this.data.process.processType=="耗材领用申请"){      
      this.getMateriaBorrowData() 
    }else if(this.data.process.processType=='资产报修申请'){
      this.getAssetRepairDetail()
    }else if(this.data.process.processType=='资产归还申请'){
      this.getAssetReturnDetail()
    }else{
      wx.showToast({
        title: '参数错误',
        icon: 'none'
      });
    }
    
  },
  //资产借用：
  getAssetBorrowData(){
    getAssetBorrowInfo(this.data.process.businessId)
    .then(res=>{
      console.log('资产',res)
      //基础数据
      let baseList = {
        "title":res.data.username+" 提交的 "+this.data.process.processType,
        "approveType":this.data.process.processType,
        "approveStatus":this.data.process.status,
        items:[
          {label:"单据号",value:this.data.process.code},
          {label:"借用人",value:res.data.username},
          {label:"借用人部门",value:res.data.deptName},
          {label:"借用时间",value:res.data.createTime},
          {label:"归还时间",value:res.data.expectedReturn},
          {label:"借用后位置",value:res.data.locationName},
          {label:"备注",value:!res.data.usagePurpose?"-":res.data.usagePurpose},
        ]
      }
      //列表数据[{label:"",value:""}],[]
      let dataList = []
      for(let i=0;i<res.data.assets.length;i++){
        let list = [
          {label:`第${i+1}条`,value:''},
          {label:"资产编码",value:res.data.assets[i].assetCode},
          {label:"资产名称",value:res.data.assets[i].name},
          {label:"资产分类",value:res.data.assets[i].categoryName},
          {label:"规格型号",value:res.data.assets[i].model},
          {label:"位置",value:res.data.assets[i].locationName},
        ]
        dataList.push(list)
      }
      this.setData({
        baseList:baseList,
        dataList:dataList
      })
    })
  },
  //耗材借用
  getMateriaBorrowData() {   
    getMateriaBorrowInfo(this.data.process.businessId,1)
    .then(res=>{
      console.log('耗材',res)
      //基础数据
      let baseList = {
        "title":res.data.username+" 提交的 "+this.data.process.processType,
        "approveType":this.data.process.processType,
        "approveStatus":this.data.process.status,
        items:[
          {label:"单据号",value:this.data.process.code},
          {label:"领用人",value:res.data.username},
          {label:"领用人部门",value:res.data.deptName},
          {label:"借用时间",value:res.data.createTime},
          {label:"经办人",value:res.data.operatorName},
          {label:"出库仓库",value:res.data.locationName},
          {label:"备注",value:!res.data.usagePurpose?"-":res.data.usagePurpose},
        ]
      }
      //列表数据
      let dataList = []
      for(let i=0;i<res.data.materialBorrowVoList.length;i++){
        let list = [
          {label:`第${i+1}条`,value:''},
          {label:"耗材编码",value:res.data.materialBorrowVoList[i].code},
          {label:"耗材名称",value:res.data.materialBorrowVoList[i].name},
          {label:"耗材分类",value:res.data.materialBorrowVoList[i].categoryName},
          {label:"规格型号",value:res.data.materialBorrowVoList[i].specification},
          {label:"单位",value:res.data.materialBorrowVoList[i].unit},
          {label:"出库仓库",value:res.data.materialBorrowVoList[i].warehouseName},
          {label:"当前仓库",value:res.data.materialBorrowVoList[i].quantity},
          {label:"领用数量",value:res.data.materialBorrowVoList[i].materialNum},
          {label:"备注",value:!res.data.materialBorrowVoList[i].materialDesc?"-":res.data.materialBorrowVoList[i].materialDesc},
        ]
        dataList.push(list)
      }
      this.setData({
        baseList:baseList,
        dataList:dataList
      })
    })
  },

  //资产报修
  getAssetRepairDetail(){
    getAssetRepairDetailInfo(this.data.process.businessId)
    .then(res=>{
      
      //基础数据
      let baseList = {
        "title":res.data.username+" 提交的 "+this.data.process.processType,
        "approveType":this.data.process.processType,
        "approveStatus":this.data.process.status,
        items:[
          {label:"单据号",value:this.data.process.code},
          {label:"维修人",value:res.data.username},
          {label:"报修人部门",value:res.data.deptName},
          {label:"报修时间",value:res.data.createTime},
          {label:"送检地点",value:res.data.locationName},
          {label:"备注",value:!res.data.faultDesc?"-":res.data.faultDesc},
        ]
      }
      //列表数据[{label:"",value:""}],[]
      let dataList = []
      for(let i=0;i<res.data.assets.length;i++){
        let list = [
          {label:`第${i+1}条`,value:''},
          {label:"资产编码",value:res.data.assets[i].assetCode},
          {label:"资产名称",value:res.data.assets[i].name},
          {label:"资产分类",value:res.data.assets[i].categoryName},
          {label:"规格型号",value:res.data.assets[i].model},
          {label:"位置",value:res.data.assets[i].locationName},
        ]
        dataList.push(list)
      }
      this.setData({
        baseList:baseList,
        dataList:dataList
      })
    })
  },
//资产归还
getAssetReturnDetail(){
  getAssetReturnDetailInfo(this.data.process.businessId)
    .then(res=>{      
      //基础数据
      let baseList = {
        "title":this.data.process.startUserName+" 提交的 "+this.data.process.processType,
        "approveType":this.data.process.processType,
        "approveStatus":this.data.process.status,
        items:[
          {label:"单据号",value:this.data.process.code},
          {label:"申请人",value:this.data.process.startUserName},
          {label:"归还后部门",value:res.data.deptName},
          {label:"归还时间",value:res.data.createTime},
          {label:"归还后位置",value:res.data.locationName},
          {label:"备注",value:!res.data.faultDesc?"-":res.data.faultDesc},
        ]
      }
      //列表数据[{label:"",value:""}],[]
      let dataList = []
      for(let i=0;i<res.data.assets.length;i++){
        let list = [
          {label:`第${i+1}条`,value:''},
          {label:"资产编码",value:res.data.assets[i].assetCode},
          {label:"资产名称",value:res.data.assets[i].name},
          {label:"资产分类",value:res.data.assets[i].categoryName},
          {label:"规格型号",value:res.data.assets[i].model},
          {label:"位置",value:res.data.assets[i].locationName},
        ]
        dataList.push(list)
      }
      this.setData({
        baseList:baseList,
        dataList:dataList
      })
    })
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})